package com.iengoo.spacewar;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zpym
 * @CopyRight (C) http://www.iengoo.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-12-26 20:21
 */
public class GridContainer {
    // 横排几个Grid
    public static final int numX = (Config.PANEL_WIDTH / Grid.WIDTH) + 1;
    // 竖排几列Grid
    public static final int numY = Config.PANEL_HEIGHT / Grid.HEIGHT + 1;
    private static List<Grid> gridList = new ArrayList<>();

    public static GridContainer instance = new GridContainer();

    private GridContainer() {
    }

    public static synchronized GridContainer getInstance() {
        return instance;
    }

    public void add(Grid g) {
        synchronized (gridList) {
            gridList.add(g);
        }
    }

    public void empty() {
        synchronized (gridList) {
            gridList.removeAll(gridList);
        }
    }

    public void remove(Mine mine) {
        synchronized (gridList) {
            gridList.remove(mine);
        }
    }

    public int size() {
        synchronized (gridList) {
            return gridList.size();
        }
    }

    public Grid get(int index) {
        synchronized (gridList) {
            return gridList.get(index);
        }
    }
}
